﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;

namespace DataAccess
{
    public class DanhMuc_Info
    {
        public int ID { get; set; }
        public int DanhMucCha { get; set; }
        public string TenDanhMuc { get; set; }
        public int SoThuTu { get; set; }
        public bool HoatDong { get; set; }


        public static List<DanhMuc_Info> DanhMucs_LayDanhMucCon(int IDcha, bool HoatDong)
        {
            return CBO.FillCollection<DanhMuc_Info>(DataProvider.Instance.ExecuteReader("sp_DanhMucs_LayDanhMucCon", IDcha, HoatDong));
        }

        public static List<DanhMuc_Info> DanhMucs_LayTatCaDanhMucCon(bool HoatDong)
        {
            return CBO.FillCollection<DanhMuc_Info>(DataProvider.Instance.ExecuteReader("sp_DanhMucs_LayTatCaDanhMucCon",  HoatDong));
        }

        public static DanhMuc_Info DanhMuc_Chon(int ID)
        {
            return CBO.FillObject<DanhMuc_Info>(DataProvider.Instance.ExecuteReader("sp_DanhMuc_Chon", ID));
        }
        public static List<DanhMuc_Info> DanhMucs_ChonTatCa()
        {
            return CBO.FillCollection<DanhMuc_Info>(DataProvider.Instance.ExecuteReader("sp_DanhMucs_ChonTatCa"));
}

        public static List<DanhMuc_Info> DanhMucs_LayDanhMucCha(bool trangthai)
        {
            return CBO.FillCollection<DanhMuc_Info>(DataProvider.Instance.ExecuteReader("sp_DanhMucs_LayDanhMucCha", trangthai));
        }


        public static bool DanhMuc_Them(int DanhMucCha, string TenDanhMuc, int SoThuTu, bool HoatDong)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_DanhMuc_Them", DanhMucCha, TenDanhMuc, SoThuTu, HoatDong);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool DanhMuc_CapNhat(int ID, int DanhMucCha, string TenDanhMuc, int SoThuTu, int HoatDong)
        {
            try
            {
                object rs = DataProvider.Instance.ExecuteNonQuery("sp_DanhMuc_CapNhat", ID, DanhMucCha, TenDanhMuc, SoThuTu, HoatDong);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public static bool DanhMuc_Xoa(int ID)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("sp_DanhMuc_Xoa", ID);
                return rs > 0;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}